import { getLocalIP } from '@/utils/ip'
import request from '@/utils/request'

export const list = (pageNum, pageSize, experimentName = null) => {
  return request.get(`/student/work/workPage?pageNum=${pageNum}&pageSize=${pageSize}&experimentName=${experimentName}`)
}

export const uploadFace = (formData) => {
  return request.post('/common/uploads', formData, {
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

export const videoList = (pageNum, pageSize, fileName = nul) => {
  return request.get(`/student/videoFile/turnoverBoxPage?pageNum=${pageNum}&pageSize=${pageSize}&fileName=${fileName}`)
}

export const updateStartPic = (obj) => {
  return request.put('/student/work/setStartExperimentPicture', {
    ...obj
  })
}

export const updateEndPic = (obj) => {
  return request.put('/student/work/setEndExperimentPicture', {
    ...obj
  })
}

export const uploadBase64 = (base64) => {
  return request.post('/common/uploadBaseString', base64)
}

export const facial = (obj) => {
  return request.post('/student/work/facial', {
    ...obj
  })
}

export const getPaperDetail = (id) => {
  return request.get(`/student/testPaperDetails/getById/${id}`)
}

export const apiWorkFile = (id) => {
  return request.get('/student/work/workFilesVO?workId=' + id)
}

export const apiStudentSaveWork = (id, currentHtml) => {
  return request.put(`/student/testPaperDetails/submitTestPaper`, {
    id,
    studentTestPaperContent: currentHtml,
    testPaperStatus: 1
  })
}

export const apiStudentWorkSubmit = (id) => {
  return new Promise((resolve, reject) => {
    getLocalIP().then(ip => {
      request.post(`/student/work/submitWork?id=${id}&submitIP=${ip}`).then(res => {
        resolve(res)
      }).catch(reject)
    }).catch(reject)
  })
}
